package org.pp.controller;


import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.pp.core.PageBean;
import org.pp.core.Result;
import org.pp.dto.PageDto;
import org.pp.miniapp.dto.UserInfoUpdate;
import org.pp.service.IPpUserService;
import org.pp.vo.MiniappGoodsVo;
import org.pp.vo.MiniappLoginVo;
import org.pp.vo.MiniappUserInfoVo;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Slf4j
public class PpUserController {

    @Autowired
    IPpUserService userService;



    @PostMapping("/login")
    @Operation(summary = "授权登陆")
    public Result<MiniappLoginVo> login(@RequestParam(value = "code") String code){
        MiniappLoginVo vo= userService.login(code);

        return Result.ok(vo);
    }

    @PostMapping("/info/update")
    @Operation(summary = "设置用户信息")
    public Result<MiniappUserInfoVo> infoUpdate(@RequestBody UserInfoUpdate dto){
        return Result.ok(userService.infoUpdate(dto));
    }

    @PostMapping("/info")
    @Operation(summary = "获取用户信息")
    public Result<MiniappUserInfoVo> info(){
        MiniappUserInfoVo vo= userService.info();
        return Result.ok(vo);
    }

    @PostMapping("/collect")
    @Operation(summary = "搜藏/取消")
    public Result<Boolean> collect(@RequestParam(required = true)  Long goodsId){
        Boolean res= userService.collect(goodsId);
        return Result.ok(res);
    }

    @GetMapping("/collect")
    @Operation(summary = "获取搜藏状态")
    public Result<Boolean> getCollect(@RequestParam(required = true)  Long goodsId){
        Boolean res= userService.getCollect(goodsId);
        return Result.ok(res);
    }

    @GetMapping("/collect/list")
    @Operation(summary = "分页查询收藏列表")
    public Result<PageBean<MiniappGoodsVo>> getCollectPageList(@ParameterObject  PageDto dto){
        PageBean<MiniappGoodsVo>res= userService.getCollectPageList(dto);
        return Result.ok(res);
    }
}
